<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>ZhongKui WAF</title>
<script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<style>
    body{font-family:Arial,sans-serif;background-color:#f5f5f5;margin:0;padding:0}
    .container{width:80%;max-width:700px;margin:50px auto;text-align:center;padding:30px}
    .message{font-size:1.3em;font-weight:bold;color:#23292e;margin-bottom:15px}
    .progress-bar{left:0;top:0;width:0;max-width:100%;height:5px;border-radius:20px;text-align:right;background-color:#16b777;transition:all .3s;-webkit-transition:all .3s}
</style>
</head>
<body>
<div class="container">
    <div class="message" id="message">请稍候，正在进行浏览器安全检测。</div>
    <div class="progress-bar"></div>
</div>
<script>
    var data = {};
    try {
        data = JSON.parse('$request_data');
    } catch(e) {
        data = $request_data;
    }
    var headers = {};
    try {
        headers = JSON.parse('$request_headers');
    } catch(e) {
        headers = $request_headers;
    }
    var result = $formula;

    function verifyPass(data) {
        $.ajax({
            url: window.location.href,
            type: data.method,
            headers: headers,
            data: data.body,
            success: function(response) {
                document.open();
                document.write(response);
                document.close();
            },
            error: function(xhr, status, error) {
                $('#message').text('请求出错，请刷新页面重试');
            }
        });
    }

    function verify(data) {
        result = result.toString().slice(0, 10);
        $.ajax({
            url: '/captcha/challenge?r=' + Math.random(),
            type: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Captcha-Sign': data['Captcha-Sign'],
                'Captcha-Time': data['Captcha-Time']
            },
            data: {'captcha_result': result},
            dataType: "json",
            success: function (response) {
                if (response.result == "success") {
                    verifyPass(data);
                } else {
                    $('#message').text('验证失败，请刷新页面重试');
                }
            },
            error: function (xhr, status, error) {
                $('#message').text('请求出错，请刷新页面重试');
            }
        });
    }

    $(function() {
        var div = document.querySelector('.progress-bar');
        var totalDuration = 3000;
        var currentWidth = 0;
        var increment = 100 / totalDuration * 100;

        var intervalId = setInterval(function() {
            currentWidth += increment;
            if (currentWidth >= 100) {
                currentWidth = 100;
                clearInterval(intervalId);
                verify(data);
            }
            div.style.width = currentWidth + '%';
        }, 100);
    });
</script>
</body>
</html>